package com.or.excersise.startwithmatcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BasicPrefixFilter {


    public BasicPrefixFilter(String[] data) {
        this.data = data;
        Arrays.sort(data);
    }

    private final String[] data;
    
    public String[] match(String prefix) {
        List<String> result = new ArrayList<String>();
        for (int i = 0; i < data.length; i++) {
            String word = data[i];
            if( word.startsWith(prefix) ) {
               result.add(word); 
            }
        }
        
        return result.toArray(new String[]{}); 
    }     

}
